using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;

namespace Lync.Widget.Library.Configuration
{
    public class ActiveDirectoryGroupElement : ConfigurationElement, IActiveDirectoryGroup
    {
        [ConfigurationProperty("id", IsRequired = true, IsKey = true)]
        public string Id
        {
            get
            {
                return this["id"] as string;
            }
            set
            {
                this["id"] = value;
            }
        }

        [ConfigurationProperty("name", IsRequired = true)]
        public string Name
        {
            get
            {
                return this["name"] as string;
            }
            set
            {
                this["name"] = value;
            }
        }

        [ConfigurationProperty("timetowait", IsRequired = false)]
        public int TimeToWaitInSeconds
        {
            get { return Convert.ToInt32(this["timetowait"]); }
            set
            {
                this["timetowait"] = value;
            }
        }

        [ConfigurationProperty("huntgroupquantity", IsRequired = false)]
        public int HuntgroupQuantity
        {
            get { return Convert.ToInt32(this["huntgroupquantity"]); }
            set
            {
                this["huntgroupquantity"] = value;
            }
        }

        [ConfigurationProperty("distinguishedname", IsRequired = true)]
        public string DistinguishedName
        {
            get
            {
                return this["distinguishedname"] as string;
            }
            set
            {
                this["distinguishedname"] = value;
            }
        }      
        public IList<IActiveDirectoryGroupMember> Members
        {
            get
            {
                return GroupMembers != null ? GroupMembers.Cast<IActiveDirectoryGroupMember>().ToList() : null;
            }
        }

        [ConfigurationProperty("Members")]
        private ActiveDirectoryGroupMemberElementCollection GroupMembers
        {
            get
            {
                var temp = this["Members"] as ActiveDirectoryGroupMemberElementCollection;
                return temp;
            }
        }
    }
}